package com.daguchuangyi.erp_android.productlist.widget;

import android.content.Context;
import android.content.Intent;
import android.support.constraint.ConstraintLayout;
import android.util.AttributeSet;

import com.daguchuangyi.erp_android.ErpApplication;
import com.daguchuangyi.erp_android.R;
import com.daguchuangyi.erp_android.productlist.scan.ScanActivity;
import com.daguchuangyi.erp_android.productlist.scan.ScanNewActivity;
import com.daguchuangyi.erp_android.search.SearchActivity;
import com.daguchuangyi.erp_android.util.PermissionUtils;
import com.jude.utils.JUtils;

/**
 * Created by lijianjian on 2018/3/4.
 */

public class SearchHintView extends ConstraintLayout {
    public SearchHintView(Context context) {
        super(context);
        init(context);
    }

    public SearchHintView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public SearchHintView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        inflate(context, R.layout.view_search_hint_layout, this);
        setBackgroundResource(R.drawable.search_hint_view_bg);
        setOnClickListener(v -> {
            Intent intent = new Intent(getContext(), SearchActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getContext().startActivity(intent);
        });
        findViewById(R.id.scan_icon).setOnClickListener(v -> {
            if (PermissionUtils.isCameraCanUse()) {
                Intent intent = new Intent(ErpApplication.getAppContext(), ScanNewActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getContext().startActivity(intent);
            } else {
                JUtils.Toast("无法拍照,请检查权限设置");
            }
        });
    }
}
